import { createApp } from 'vue'
// import {ElPagination,ElTable,ElTableColumn} from 'element-plus'
import ElementPlus, { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import {Document} from '@element-plus/icons'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import {StateKey, store} from './store'
// import 'element-plus/lib/theme-chalk/index.css';
// import 'element-plus/lib/theme-chalk/base.css';

// @ts-ignore
import VMdEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
// @ts-ignore
import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';
import '@kangc/v-md-editor/lib/theme/style/github.css';

// highlightjs
import hljs from 'highlight.js';

VMdEditor.use(githubTheme, {
    Hljs: hljs,
});

const vm=createApp(App)
vm.use(ElementPlus)
vm.use(VMdEditor)
vm.component('document',Document)
// vm.component(ElTable.name,ElTable)
// vm.component(ElTableColumn.name,ElTableColumn)
// vm.component(ElPagination.name,ElPagination)

vm.use(router)

//改造我们main.ts文件  添加插件导入
vm.use(store,StateKey)

// const plugins=[ElLoading,ElMessage,ElMessageBox]
// plugins.forEach(plugin=>{
//   vm.use(plugin)
// })
vm.mount('#app')


// 为了能够获取全局的store 的数据仓库  不能将路由的拦截器放在路由模块的index.js文件下，应该放置到当前的main.ts下
router.beforeEach((to, from, next) => {
  if (
    /\/admin/i.test(to.path) &&
    (!store.state.user.id )//|| store.state.user.role !== 'Admin'
  ) {
    next('/login');
    return;
  }
  next();
});